<?php

namespace App\Model;

use PhalApi\Model\DataModel;



class IdcardInfo extends DataModel
{

    protected function getTableName($id)
    {
        return 'idcard_info_list';
    }


    //存入数据
    public function checkIdCardInfo($data)
    {
        //重构新数组
        $new_data = array();
        foreach ($data as $k => $v){
            if ($v){
                $new_data[$k]=$v;
            }
        }

        //查询身份证号
        $IdNum = $new_data['IdNum'];
        $unit = $new_data['unit'];
        if($IdNum){
            $new_data['update_time'] = date("Y-m-d H:i:s", time());
            //查询结果
            $info = $this->getORM()->select('id','Name', 'phone', 'IdNum', 'pic','filePath','Address',"likes")->where(array(
                'IdNum' => $IdNum,
                'unit' => $unit
            ))->fetchOne();
            //如果有信息,就返回相关数组
            if ($info) {
                $this->getORM()->where('id', $info['id'])->update($new_data);
                $new_data['id'] = $info['id'];
                if( $info['filePath'] ){
                    $new_data['filePath'] = $info['filePath'];
                }
                if( $info['pic'] ){
                    $new_data['pic'] = $info['pic'];
                }
                if( $info['likes'] ){
                    $new_data['likes'] = $info['likes'];
                }
                return $new_data;
            }
            $new_data['create_time'] = date("Y-m-d H:i:s", time());
            return $this->getORM()->insert($new_data);
        }
    }


}
